package com.fitness.front.controller;

import com.fitness.front.modal.response.ServerResponseEntity;
import com.fitness.front.service.impl.common.RecommenderServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/api/v1/front/fitness")
@RequiredArgsConstructor
public class FitnessPlanController {

    private final RecommenderServiceImpl recommenderService;

    @RequestMapping("/plan")
    public ServerResponseEntity<Map<String,Number>> getFitnessPlan(@RequestParam("age")Integer age,
                                                                  @RequestParam("gender")Integer gender,
                                                                  @RequestParam("height")Double height,
                                                                  @RequestParam("weight")Double weight,
                                                                  @RequestParam(value="level")Integer level) {
        Map<String,Number> data = recommenderService.recommendPlan(age,gender,height,weight,level);
        if(data == null){
            throw new RuntimeException("生成健身计划失败");
        }
        return ServerResponseEntity.success(data);
    }
}
